<?php
declare (strict_types = 1);
namespace app\validate;
use think\Validate;

class User extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */	
	protected $rule = [
	    'username'          =>  'require|min:2|max:10|chsDash|unique:admin',
        //'__token__'         =>  'require|token',
        'password'          =>  'require|min:6',
        'passwordnot'       =>  'require|confirm:password',
        'newpasswordnot'    =>  'min:6|requireWith:newpassword|confirm:newpassword',
        'url'              =>   'require',
        'text'              =>   'require',
        'name'              =>    'require',
        'alg'              =>    'require',
        'host'          =>'require',
    ];
    
    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */	
    protected $message = [
        'username.require'      => '用户名不得为空~',
        'username.min'          => '用户名不得小于 2 位~',
        'username.max'          => '用户名不得大于 10 位~',
        'username.chsDash'      => '用户名只能是汉字、字母、数字或下划线以及破折号~',
        'username.unique'       => '用户名已存在~',
        'password.require'      => '密码不得为空~',
        'password.min'          => '密码不得小于 6 位~',
        'passwordnot.require'   => '密码确认不得为空~',
        'passwordnot.confirm'   => '密码确认和密码不一致~',
        '__token__.require'     => '令牌不得为空~',


        'newpasswordnot.min'            => '新密码不得小于 6 位~',
        'newpasswordnot.requireWith'    => '新密码不得为空~',
        'newpasswordnot.confirm'        => '新密码确认不一致~',
        'text.require'                  => '广告文字不得为空~',
        'url.require'                   => '广告链接不得为空~',

        'name.require'          =>  '算法名称不得为空',
        'alg.require'          =>  '算法名称不得为空',
        'host.require'          =>  '域名不得为空',


    ];

    //场景验证
    protected $scene = [
        'insert'    =>  ['username', 'password', 'passwordnot', '__token__'],
        'edit'      =>  ['__token__', 'newpasswordnot'],
        'adv'       =>  ['text','url'],
        'alg'       =>  ['name','alg'],
        'cat'       =>  ['name','url'],
        'host'       =>  ['host'],

        'hostcat'       =>  ['name','url'],
    ];


}
